﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gx.Common.Core
{
    public class DbContext : IDisposable
    {
        private SqlConnection connection;
        public SqlConnection Connection
        {
            get
            {
                if (connection == null)
                    connection = GetConnection();
                return connection;
            }
            set
            {
                connection = value;
            }
        }

        public void Dispose()
        {
            if (Connection != null)
                Connection.Dispose();
        }

        private SqlConnection GetConnection()
        {
            var conn = new SqlConnection(ConfigHelper.ConnectionStrings);
            conn.Open();
            return conn;
        }
    }
}
